package com.internetCafes.spms.web.sys.service.impl;

import com.internetCafes.spms.common.module.mongodb.MongodbBaseService;
import com.internetCafes.spms.common.module.mongodb.ReflectionUtils;
import com.internetCafes.spms.core.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.internetCafes.spms.web.sys.dao.MailSendLogMapper;
import com.internetCafes.spms.web.sys.model.MailSendLog;
import com.internetCafes.spms.web.sys.service.MailSendLogService;


/**
 * 邮件日志 MailSendLogService 实现类
 *
 * @author Sunny
 * @email rekeeper2011@hotmail.com
 * @date 2019-09-18 14:19:36
 */
@Service("mailSendLogService")
public class MailSendLogServiceImpl extends MongodbBaseService implements MailSendLogService {

    @Autowired
    private MailSendLogMapper mailSendLogMapper;

    @Override
    public MailSendLog queryObject(Long id){
        return mailSendLogMapper.findById(id);
    }

    public PageUtils page(Map<String, Object> params, int pageNo, int pageSize) {
        Query query = ReflectionUtils.getQueryMap(params);
        return mailSendLogMapper.page(pageNo,pageSize,query);
    }

    @Override
    public List<MailSendLog> queryList(Map<String, Object> params){
        return mailSendLogMapper.find(getQueryParams(params));
    }

    @Override
    public int queryTotal(Map<String, Object> map){
        int count = 0;
        List<MailSendLog> collectionsInfoEntities = mailSendLogMapper.findAll();
        if(collectionsInfoEntities != null){
            count = collectionsInfoEntities.size();
        }
        return count;
    }

    @Override
    public void save(MailSendLog collectionsInfo){
        mailSendLogMapper.save(collectionsInfo);
    }

    @Override
    public void update(MailSendLog s){
        Query query=new Query(Criteria.where("id").is(s.getId()));
        Update update= new Update().set("createBy", s.getCreateBy()).set("createTime", s.getCreateTime());
        //更新查询返回结果集的第一条
        mailSendLogMapper.findAndModify(query, update);
        //更新查询返回结果集的所有
        // mongoTemplate.updateMulti(query,update,UserEntity.class);
		/*if(result!=null)
			return result.getN();
		else
			return 0;*/
    }

    @Override
    public void delete(Long id){
        Query query=new Query(Criteria.where("id").is(id));
        mailSendLogMapper.findAndRemove(query);
    }

    @Override
    public void deleteBatch(Long[] ids){
        for(Long id:ids){
            Query query=new Query(Criteria.where("id").is(id));
            mailSendLogMapper.findAndRemove(query);
        }
    }
}